<?php

class BrandModel extends Model{
	
	public $table='brand';
	
	public $validate=array(
		array('brand','nonull','品牌名字不能为空',2,3),
	);
	
	public function get_all_data($where=null){
		
		return $this->where($where)->all();
	}
	
	public function add_data(){
		if(!$this->create()) return FALSE;
		
		$upload =new Upload();
		
		$file=$upload->upload();
		$img=new Image();
		
		$thumb=$img->thumb($file[0]['path']);
		
		$data=array(
			'brand'=>Q('post.brand'),
			'hot'=>Q('post.hot',0,'intval'),
			'logo'=>$thumb,
		);
		
		return $this->add($data);
		
	}
	
	public function delete_data($where=null){
		
		return $this->where($where)->delete();
	}
	
	public function get_one_data($where=null){
		
		return $this->where($where)->find();
	}
	
	public function edit_data($where=null){
		
		if(!$this->create()) return FALSE;
		
		$upload =new Upload();
		
		$file=$upload->upload();
		
		if($file){
			
		$img=new Image();
		
		$thumb=$img->thumb($file[0]['path']);
		}else{
			$thumb=Q('post.hidden_logo');
		}
		
		
		$data=array(
			'brand'=>Q('post.brand'),
			'hot'=>Q('post.hot',0,'intval'),
			'logo'=>$thumb,
		);
		
		return $this->where($where)->update($data);
	}
	
	
}










